# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Alex Yam <alex@alexyam.com>
pkgname=cherrytree
pkgver=1.2.0
pkgrel=0
pkgdesc="hierarchical note taking application featuring rich text and syntax highlighting"
url="https://github.com/giuspen/cherrytree"
license="GPL-3.0-or-later"
arch="all"
makedepends="
	cmake
	curl-dev
	fmt-dev
	gspell-dev
	gtkmm3-dev
	gtksourceview4-dev
	libxml++-2.6-dev
	python3
	samurai
	spdlog-dev
	sqlite-dev
	uchardet-dev
	vte3-dev
	"
checkdepends="xvfb-run gtest-dev"
subpackages="$pkgname-doc $pkgname-lang"
source="https://github.com/giuspen/cherrytree/releases/download/v$pkgver/cherrytree_$pkgver.tar.xz"
builddir="$srcdir/${pkgname}_$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		-DAUTO_RUN_TESTING=OFF \
		-DPYTHON_EXEC=/usr/bin/python3 \
		-DUSE_SHARED_GTEST_GMOCK=ON
	cmake --build build
}

check() {
	# Skip broken ExportsMultipleParametersTests.ChecksExports tests
	#
	# (run_tests_with_x_1:7077): Gtk-WARNING **: 04:05:18.849:
	#   Found an icon but could not load it. Most likely gdk-pixbuf does not
	#   provide SVG support.
	#
	# [  FAILED  ] ExportsTests/ExportsMultipleParametersTests.ChecksExports
	#   /testing/cherrytree/src/cherrytree_0.99.44/tests/data_данные
	#   /test_документ.ctb", "--export_to_html_dir")
	xvfb-run -a ctest --test-dir build \
		-E ExportsMultipleParametersTests.ChecksExports
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install

	# bundled breeze-icons
	rm -rv "$pkgdir"/usr/share/cherrytree/icons
}

sha512sums="
729e8227eb1f0616e110153ac2139cc7019ed5e1a949c8be40fd2235ee5d2e0f0b1925c57d72c9b443852e5b80a50793e4e903b7df41da8e95a172210f7ec035  cherrytree_1.2.0.tar.xz
"
